<template>
  <Layer :hideSide="true">
    <content :item="active"></content>
  </Layer>
</template>

<script setup>
import { getTrStrategyView } from "/api/TrStrategy";
// 获取当前页面的 route 参数
const route = useRoute();
const { id } = route.params;
const active = ref({ mainImg: "", items: [] });
// 使用 useAsyncData 确保数据在服务端和客户端都正确获取
const { data, error } = await useAsyncData(() => getTrStrategyView(id));
const goto404 = () => {
  // window.location.replace = '/404'
  navigateTo("/404");
  // error({ statusCode: 404, message: '页面未找到' });
};
// 根据请求结果设置 active 值
const init = (data) => {
  if (data.value?.code === 200) {
    const dataView = data.value.data;
    if (!dataView || !dataView.id) {
      return goto404();
    }
    active.value = dataView;
    const description =
      dataView.description ||
      `${dataView.tags},${active.value.title}`;
    const keywords =
      dataView.keywords ||
      `${dataView.provinceName},${dataView.cityName},${active.value.title}`;
    useHead({
      title: keywords,
      meta: [{ name: "description", content: `${dataView.provinceName},${dataView.cityName},${description}` }],
    });
  } else {
    return goto404();
  }
};

init(data);
</script>
